package com.example.tests;

import org.junit.*;
import static org.junit.Assert.*;

import com.example.data.SorterListOf;
import com.example.data.User;
import com.example.pages.UserManagementPage;

public class CreateNewUserTest extends TestBase {

	@Test
	public void createNewUser() {
		UserManagementPage userManagementPage = goToMainPage()
				.loginWithValidCredentials("admin", "admin")
				.gotoUserManagementConsole();
		
		SorterListOf<User> oldUserList = userManagementPage.getUsers();
				
		User user= new User()
		.withName("user1").withEmail("user1@test.com").withPassword("test");
		
		if (oldUserList.contains(user)){
			userManagementPage.deleteUser(user);
			oldUserList = userManagementPage.getUsers();
		}
		
		userManagementPage.createUser(user);
		
		SorterListOf<User> newUserList = userManagementPage.getUsers();
				
		assertEquals(newUserList, oldUserList.withAdded(user));
		
		userManagementPage.logout();
	}

}
